﻿using Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData.Events;
using Sustainalytics.Entities.RiskRatings;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData
{
    internal class RiskRatingEventsMapping
    {
        internal static IEnumerable<EventIndicator> Map(IEnumerable<EventIndicator> newsevents,  Dictionary<string, EventMapping> mapping)
        {
            var result = newsevents.ToList();

            Parallel.ForEach(result, newsEvent =>
            {
                if (mapping.TryGetValue(newsEvent.EventCode, out EventMapping map))
                {
                    newsEvent.CanvasCode = map.Code;
                }

            });
            return result;
        }
    }
}